package Swing;

import DD.Action;
import DD.PP;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Frame extends JFrame {


    JButton btn = new JButton("启动");
    JTextPane jtext = new JTextPane();
    JScrollPane scrollPane = new JScrollPane(jtext);
    Thread t;
    public Frame(final PP p1, final PP p2){


        setTitle("dnf航海士");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);    //置窗口是否可以关闭
        setSize(300,200);
        Container c=getContentPane();    //获取当前窗口的内容窗格
        jtext.setEditable(false);
        scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

        final JButton btn = new JButton("启动");
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());


        btn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {


                if (btn.getText() == "启动") {

                    t = new Thread(new Action(jtext,p1,p2));
                    btn.setText("停止");

                    t.start();

                }else {

                    btn.setText("启动");
                    t.interrupt();

                }
            }
        });

        panel.add(btn,BorderLayout.NORTH);
        panel.add(scrollPane,BorderLayout.CENTER);
        c.add(panel);

        setVisible(true);
    }
}
